//
//  NSObject+model.m
//  根据数据自动读取model的成员属性
//
//  Created by 李松 on 2017/11/23.
//  Copyright © 2017年 李松. All rights reserved.
//

#import "NSObject+model.h"

@implementation NSObject (model)

+ (void)createPropertyCodeWithDic:(NSDictionary *)dic{
    
    NSMutableString *str = [NSMutableString string];
    [dic enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        
        //NSLog(@"%@ %@", key, [obj class]);
        NSString *code;
        if ([obj isKindOfClass:NSClassFromString(@"__NSCFNumber")]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) int %@;", key];
        }else if ([obj isKindOfClass:NSClassFromString(@"__NSCFString")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSString *%@;", key];
        }
        else if ([obj isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;", key];
        }
        else if ([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;", key];
        }
        if (code) {
            [str appendFormat:@"\n%@\n", code];
        }
    }];
    
    NSLog(@"%@", str);

}

@end
